package com.onpositive.notes.test;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.Locale;

import com.onpositive.notes.model.INote;
import com.onpositive.notes.parser.BasicNoteParser;
import com.onpositive.notes.services.BasicNoteRegistry;

public class Launcher {
	
	public static void main(String[] args){
		
		String str = "23 october 2012 оценил наличность 5 руб\nа затем купил 1 л молоко 23, картопель 2 кило" ;
		
		BasicNoteParser parser = new BasicNoteParser() ;
		
		INote note = parser.parse(str);
		BasicNoteRegistry.getInstance().registerNote(note) ;
		
		INote result = null ;
		try {
			File f = new File( "c:/work/note.dat" ) ;
			if(f.exists())
				f.delete() ;
			
			f.createNewFile() ;
			
			ObjectOutputStream oos = new ObjectOutputStream( new FileOutputStream(f)) ;
			oos.writeObject(note) ;
			oos.close() ;
			
			ObjectInputStream ois = new ObjectInputStream( new FileInputStream(f)) ;
			Object readObject = ois.readObject();
			result = (INote) readObject ;
			
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
		
		if(result != null){
			
			String res = result.getText( new Locale("ru") ) ;			
			System.out.println(res) ;
		}
	}

}
